<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2021/3/20
 * Time: 17:52
 */

namespace api\modules\v2\controllers;

use yii;
use api\controllers\OnAuthController;
use Codeception\Module\Db;
use common\enums\StatusEnum;
use common\models\base\SearchModel;
use common\models\Books\Books;

class BooksController extends OnAuthController
{
    public $modelClass =Books ::class;

    protected $authOptional = ['index','pid'];

    /**
     * @return string|\yii\data\ActiveDataProvider
     */
    public function actionPid()
    {
        $pid = Yii::$app->request->get('cate_id');
        $membercate = Books::find()->where(['books_cate_id'=>$pid])->all();
        if(empty($membercate)){
            return "请传入books_cate_id";
        }else{
            if ($membercate){
                return $membercate;
            }else{
                return "请求失败";
            }
        }
    }
    public function actionIndex()
    {
        $books = Books::find()->all();
        if($books){
            return $books;
        }else{
            return "请求失败";
        }
    }
}